/*
Haloscan comment script
version 1.0

*/
// ==UserScript==
// @name          De-javascript haloscan comment links
// @namespace     http://meat.net/
// @description   Remove javascript:func() hrefs for haloscan, replace with real links.
// @include       http://*
// ==/UserScript==

var res = document.evaluate("//SCRIPT[starts-with(@src, 'http://www.haloscan.com/load')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
if (res.snapshotLength > 0) 
{
    var src = res.snapshotItem(0).src;
	var re = /load(?:.php\?user=([^;\/]+)|\/([^\/]+))/;
	var match = re.exec(src);
    var user = match[1] || match[2];
    var res = document.evaluate(
        "//a[starts-with(@href,'javascript:HaloScan(')]",
        document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
    );
    for (var i = 0; i < res.snapshotLength; i++) {
        var a = res.snapshotItem(i);
        a.href = 'http://www.haloscan.com/comments/' + user + '/' +
            a.href.substring(21, a.href.length - 3) + '/';
    }
}
